<?php
namespace app\backend\controller;

/**
 * 公共控制器基类
 * @package app\index\controller
 */
class Base extends \think\Controller
{
    public $create_error = '创建失败，请检查后重试';
    public $update_error = '修改失败，请检查后重试';

    public function _initialize()
    {
        $s_username = \think\Session::get('login_user');
        $c_username = \think\Cookie::get('username');
        if (empty($s_username) && empty($c_username))
        {
            $this->error('请您登录后操作...', 'login/index');
        } else if(empty($s_username)) {
            \think\Session::set('login_user', $c_username);
        }

        $auth = \think\Session::get('auth');
        if($auth !=1){
            $request = \think\Request::instance();
            if($request->controller()=="menu"){
                $this->error("没有权限");
            }
        }


        // 权限验证
        //$request = \think\Request::instance();
        //$currentAuth = $request->module().'/'.$request->controller().'/'.$request->action();
        //$flag = \app\backend\model\AuthAccess::checkAuth($account_id, $currentAuth);
        /*if(!$flag)
        {
            $this->error('没有权限');
        }*/


        // 左侧菜单栏分配数据
        $this->assign('menu_data', \app\backend\model\Menu::menuData());
        $this->assign('jsController', strtolower(\think\Request::instance()->controller()));
        $this->assign('jsAction', strtolower(\think\Request::instance()->action()));
        $this->assign('jsId',\think\Request::instance()->param('id'));
        $this->assign('empty', '<span class="h4" style="color: #f00;">暂无数据</span>');
    }
}